package com.itheima.reggie.service.impl;

import com.itheima.reggie.dao.UserDao;
import com.itheima.reggie.entity.User;
import com.itheima.reggie.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired(required = false)
    private UserDao userDao;

    @Override
    public User login(String phone, String code, String verifyCode) {
        User user = null;
        // 判断验证码是否正确
        if (code.equalsIgnoreCase(verifyCode)) {
            // 查询该用户是否存在
            user = userDao.getByPhone(phone);
            // 若不存在，帮助用户注册
            if (user == null) {
                user = new User();
                user.setPhone(phone);
                user.setStatus(1);
                userDao.save(user);
            }
        }
        return user;
    }
}
